﻿using System;
using System.IO;
using System.Data;
using System.Windows;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Input;
using System.ComponentModel;
using System.Windows.Controls;
using Sinacor.Infra.UI.Common;
using Sinacor.Infra.UI.Controls;
using Sinacor.Infra.UI.Controls.SmartClient;
using Sinacor.Infra.UI.Controls.SmartClient.Validation;

namespace Sinacor.UI.Bovespa.Movimento.View.SmartClient
{
    /// <summary>
    /// Interaction logic for RemontaCalendario.xaml
    /// </summary>
    public partial class RemontaCalendario : SinacorWindow, Presenter.IRemontaCalendarioView
    {
        #region Atributos

        private Presenter.IRemontaCalendario _presenterRemontaCalendario;

        #endregion

        #region Construtores

        public RemontaCalendario(Model.Enum.TipoSistema tipoSistema)
        {
            InitializeComponent();

            if (tipoSistema == Model.Enum.TipoSistema.Bolsa)
                _presenterRemontaCalendario = new Presenter.RemontaCalendarioBolsa(this);
            else
                _presenterRemontaCalendario = new Presenter.RemontaCalendarioOrdens(this);

            this.DataContext = _presenterRemontaCalendario;

            this.AfterInitialize += new RoutedEventHandler(RemontaCalendario_AfterInitialize);
            BtnRemontaCalendario.Click += new RoutedEventHandler(BtnRemontaCalendario_Click);
            BtnFechaTela.Click += new RoutedEventHandler(BtnFechaTela_Click);
        }

        #endregion

        #region Propriedades
        #endregion

        #region Event Handlers

        private void RemontaCalendario_AfterInitialize(object sender, RoutedEventArgs e)
        {
            _presenterRemontaCalendario.Inicializar();
        }

        private void BtnRemontaCalendario_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ShowUserWaitingProcess();
                _presenterRemontaCalendario.RemontarCalendario();
            }
            finally
            {
                HideUserWaitingProcess();
            }
        }

        private void BtnFechaTela_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        #endregion

        #region IRemontaCalendarioView Members

        public void AtualizarDataMovimento()
        {
            TxtDataMovimento.UpdateTarget(SinacorTextBox.TextProperty);
        }

        public void InformarSucesso()
        {
            SinacorMessageBox.Show(this.FindResource("Bovespa.Movimento.Message.OperacaoRealizadaSucesso").ToString(),
                                        SinacorMessageBoxButton.Ok,
                                        SinacorMessageBoxImage.Information);   
        }

        #endregion
    }
}
